function  [min_index, dist_vec, round_index_best, calibrated_moment_values] = smolayak_find_best_parameter_combination( model_option, round_index_vec,  n_row, weights )
% Usage:  smolayak_find_best_parameter_combination( )
% This function finds the best parameter combination, using the simulation results under path "file_path".  Round_index
% indicates the sheet number of the corresponding spread sheet.  model_option.model_index refers to one of the three
% models: (1) benchmark model;  (2) rational model; (3) behavioral model.

model = model_option.model_name;

if(isfield(model_option,'scenario'))
    result_file_name= strcat('calibration_smolayak_', model_option.scenario ,'.xlsx');
else
    result_file_name= strcat('calibration_smolayak_', model ,'.xlsx');
end
results=[];
for(round_index=round_index_vec)
results =  [results;
    readtable( result_file_name, 'Sheet', round_index ,  'Range',   [ 'M5:S', num2str(n_row+4)]    ,'ReadVariableNames',false).Variables];
end

target_moment_file = 'moment_target.xlsx'; 
target_values =  readtable( target_moment_file, 'Sheet',1,  'Range',  ['B3:B9'] ,'ReadVariableNames',false).Variables';

dist_fun =  @(moment_values)    nanmean(  weights./sum(weights) .* abs( moment_values - target_values ) ./ abs(target_values ) );
N_total = size(results,1);
dist_vec = zeros( N_total, 1 );

for( i = 1:N_total )
    dist_vec(i) =  dist_fun( results(i,:)  );
end

other_moment_values=[];
for(round_index=round_index_vec)
    other_moment_values = [other_moment_values; 
    readtable( result_file_name, 'Sheet', round_index ,  'Range',   [ 'M5:AF', num2str(n_row+4)]    ,'ReadVariableNames',false).Variables];
end

[~, min_index_in_all] = min( dist_vec );

round_index_best = ceil(min_index_in_all/n_row);
min_index = min_index_in_all - (round_index_best-1)*n_row;

calibrated_moment_values = results(min_index_in_all,:);

